package controller;

import dao.CarDAOImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/delete_car")
public class DeleteCarServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf8");
        resp.setContentType("application/json;charset=utf8");
        resp.setCharacterEncoding("utf8");

        //获取打印输出流,向网页输出内容
        PrintWriter writer = resp.getWriter();

        int id =Integer.parseInt(req.getParameter("id"));
        CarDAOImpl dao = new CarDAOImpl();
        int i = dao.deleteCarById(id);
        if (i>0){
            writer.print("删除成功");
        }else{
            writer.print("删除失败");
        }
        writer.close();
    }
}
